<?php

namespace eu\freeplace\page;

use eu\freeplace\core\Utils as Utils;

/**
 * Dynamic Loader for CSS Files.
 *
 * @author Elmar Dott
 * @version 1.0
 */
class CSSLoader {

    /** Class Name */
    const CLASS_NAME = "CSSLoader";

    /**
     * Default Constructor
     * @global Logger $logger
     */
    public function __construct() {
        global $logger;
        $logger->log("Calling instance of ".self::CLASS_NAME."()", "NOTICE");
    }

    /**
     * Render the complete CSS Inclusions of the Webapp.
     *
     * @global Logger $logger
     * @return String fullCSSinclusion
     */
    public function render() {
        global $logger;
        $logger->log(self::CLASS_NAME."().loadFiles()", "DEBUG");
        return trim($this->loadFiles());
    }

    // fetch all CSS Files in the CSS Folder
    private function loadFiles() {

        global $utils;
        $css = "";
        $files = $utils->readDir('css/');
        $cnt   = sizeof($files);
        if($cnt > 0) {
            for($i=0; $i < $cnt; $i++) {
                $css .= "<link rel='stylesheet' href='css/".$files[$i]."' type='text/css' media='screen' />\n";
            }
        }
        return $css;
    }

}//CLASS

?>